package com.scedu.service.impl;

import com.scedu.dto.OrderDTO;
import com.scedu.enums.ResultEnums;
import com.scedu.exception.SellException;
import com.scedu.service.BuyerService;
import com.scedu.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service //业务层
public class BuyerServiceImpl implements BuyerService {
    @Autowired OrderServiceImpl orderService;
    @Override
    public OrderDTO findeOrderOne(String openid, String orderId) {
        OrderDTO orderDTO= orderService.findOne(orderId);
        if (orderDTO==null){
            return  null;
        }
        //判断返回的openid和传递的openid是否相同
        if (!orderDTO.getOrderOpenid().equalsIgnoreCase(openid)){
           throw new SellException(ResultEnums.OPENDI_ERROR);
        }
        return (orderDTO);
    }

    @Override
    public OrderDTO calcelOrder(String openid, String orderId) {
        OrderDTO orderDTO=orderService.findOne(orderId);
        if (orderDTO==null){
            throw new SellException(ResultEnums.ORDER_NOT_EXIT_ERROR);
        }
        //判断返回的openid和传递的openid是否相同
        if (!orderDTO.getOrderOpenid().equalsIgnoreCase(openid)){
            throw new SellException(ResultEnums.OPENDI_ERROR);
        }
        orderService.cancel(orderDTO);
        return (orderDTO);
    }
}
